from django.contrib.auth.hashers import make_password, check_password
from django.db import models


class AXFUser(models.Model):

    username = models.CharField(max_length=32, unique=True, null=False)
    _password = models.CharField(max_length=256)
    phone = models.CharField(max_length=16, unique=True, null=False)
    icon = models.CharField(max_length=256, null=True, default="")
    is_delete = models.BooleanField(default=False)

    class Meta:
        db_table = "axf_user"

    @property
    def password(self):
        return self._password

    @password.setter
    def password(self, value):
        # 对密码进行hash
        self._password = make_password(value)

    def verify_password(self, value):
        # 提供验证密码策略
        return check_password(value, self._password)
